package views
{
	import flash.filesystem.File;
	import flash.utils.setTimeout;
	
	import inerface.IClearAllPanel;
	
	import main.LocalStoreInfo;
	import main.ViewSubBase;
	
	import panel.clearAll.ClearAllPanel;
	
	public class ClearAllView extends ViewSubBase
	{
		private var _panel:IClearAllPanel;
		
		public function ClearAllView()
		{
		}
		
		public override function show():void
		{
			render();
		}
		
		protected override function render():void
		{
			if(_panel == null){
				_panel = new ClearAllPanel;
				_panel.init(view.layout.stage,view.resourceLoader,view.lang,view.uri);
				_panel.clickFunc = clickAndClear;
				_panel.clearCache = cacheClear;
			}
			
			addView(_panel);
		}
		
		private function clickAndClear():void
		{
			view.alert.showAlert("将清理SD卡上已下载的旧资源，并且清理缓存，是否继续？","确定","取消",function ():void{
				var directory:File = File.documentsDirectory.resolvePath("iWeiHai");
				if(directory.exists == false){
					setTimeout(function ():void{view.alert.showAlert("<b>资源已清理</b>","返回");},200);
					return;
				}else{
					
					var store:LocalStoreInfo = new LocalStoreInfo;
					store.clearInfo();
					
					directory.deleteDirectory(true);
					setTimeout(function ():void{view.alert.showAlert("<b>清理成功</b>","返回");},200);
				}
			}
			);
		}
		
		private function cacheClear():void              //测试更新
		{
//			data.update.getUpdateList(1000);
		}
		
		public function upgradeAndClear():void
		{
			
		}
		
		public override function clear():void
		{
			if(_panel){
				_panel.clear();
				_panel = null;
			}
		}
		
		public override function close():void
		{
			closeView(this);
		}
	}
}